Skip to content

Support for configuring the browser fetch credentials mode in BrowserClient.#1937

Open
mauriceraguseinit wants to merge 2 commits into
dart-lang:masterfrom
mauriceraguseinit:master
Open

Support for configuring the browser fetch credentials mode in BrowserClient.#1937
mauriceraguseinit wants to merge 2 commits into
dart-lang:masterfrom
mauriceraguseinit:master

Conversation

@mauriceraguseinit

Copy link
Copy Markdown

This PR adds support for configuring the browser fetch credentials mode in BrowserClient.

Currently BrowserClient only exposes a boolean withCredentials option, which maps to either same-origin (when false) or include (when true). The browser fetch API, however, supports a third credentials mode, omit, which cannot be expressed through the existing boolean API. The only way to use omit today is to fork or copy BrowserClient and change the RequestInit manually.

Closes #1936.

What this changes

  • Adds a new BrowserCredentialsMode enum with the values omit, sameOrigin, and include, matching the three credentials modes defined by the [Fetch standard](https://fetch.spec.whatwg.org/#requestcredentials).
  • Adds a credentialsMode property and constructor parameter to BrowserClient, defaulting to BrowserCredentialsMode.sameOrigin to preserve the existing default behavior.
  • The RequestInit.credentials value is now derived from credentialsMode.

Backward compatibility

  • The existing withCredentials property is kept and continues to work, but is now deprecated because a boolean cannot represent all three credentials modes.
  • It is implemented as a compatibility adapter on top of credentialsMode:
    • the getter returns true only when credentialsMode is include;
    • the setter maps true to include and false to sameOrigin.
  • Existing code such as BrowserClient()..withCredentials = true keeps producing the same fetch behavior as before.

New usage

final client = BrowserClient(
  credentialsMode: BrowserCredentialsMode.omit,
);

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.

@google-cla

google-cla Bot commented Jun 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose the browser fetch credentials mode in BrowserClient

1 participant